using Microsoft.Xna.Framework;

namespace MicroStar
{
    /// <summary>
    /// Emitter to emit particles in a rectangular pattern
    /// </summary>
    public class RectEmitter : Emitter
    {
        internal override void Emit(double elapsedMilliseconds, Vector2 position)
        {
            int numParticles = RandomEmissionAmount;

            for (int i = 0; i < numParticles && FreeParticles.Count > 0; i++)
            {
                Particle particle = FreeParticles.Dequeue();

                float halfWidth = Width / 2f;
                float halfHeight = Height / 2f;

                Vector2 offset = Vector2.Zero;
                offset.X = (float)((halfWidth - (-halfWidth)) * Random.NextDouble() + (-halfWidth));
                offset.Y = (float)((halfHeight - (-halfHeight)) * Random.NextDouble() + (-halfHeight));

                Vector2 emitPosition = Vector2.Add(position, offset);
                InitializeParticle(ref particle, emitPosition, elapsedMilliseconds);
            }
        }

        /// <summary>
        /// Gets or sets the width of the emitter
        /// </summary>
        public int Width { get; set; }

        /// <summary>
        /// Gets or sets the height of the emitter
        /// </summary>
        public int Height { get; set; }
    }
}
